package com.xy.breakfast.mapper;

import com.xy.breakfast.entity.Products;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

@Mapper
public interface ProductsMapper extends BaseMapper<Products>{

    @Override
    @Select("SELECT * FROM products WHERE id = #{id}")
    @Results({
            @Result(property = "ordersId", column = "orders_id", jdbcType = JdbcType.INTEGER),
            @Result(property = "takeTime", column = "take_time", jdbcType = JdbcType.INTEGER),
            @Result(property = "isPack", column = "is_pack", jdbcType = JdbcType.INTEGER),
    })
    public Products getById(int id);

    @Override
    @Insert("INSERT INTO products (orders_id,take_time,is_pack,address,state) " +
            "VALUES (#{ordersId},#{takeTime}, #{isPack},#{address}, #{state})")
    @Options(useGeneratedKeys = true, keyProperty = "id") //设置自增主键
    public void save(Products t);

    @Override
    public void deleteById(int id);

    @Override
    public void update(Products t);

    @Override
    public List<Products> getAll();

    @Override
    public List<Products> getPage(int start,int end);
}
